package xt.outfood.mail;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @author 小小爱欧
 * @date 2022/7/12 15:07
 * 简单邮件发送，只发送标题和内容
 */
@Slf4j
@Component
public class SendMailServiceImpl implements SendMailService {
    //封装发送邮件的客户端送
    @Autowired
    private JavaMailSender javaMailSender;
    //发送人
    private String from="428904315@qq.com";
    //接收人
    private String to;
    //标题
    private String subject="移动支付验证码";
    //正文
    private String context="您好，您的验证码是:";
    @Override
    public void sendMail(String emial,String code) {
        SimpleMailMessage message=new SimpleMailMessage();
        to=emial;
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(context+code);
        log.info("发送的消息为：{}",message);

        javaMailSender.send(message);
        log.info("邮件发送成功");

    }
}
